//
//  SWTodayContentReq.swift
//  ChildStory
//
//  Created by linhan on 2016/12/22.
//  Copyright © 2016年 Aiya. All rights reserved.
//

import Foundation
class SWTodayContentFetchReq: SWBaseRequest
{
    override init()
    {
        super.init()
        api = SWRequestAPI.TodayContentFetch
    }
    
    override func JSONToModel(_ json:JSON, JSONString:String, JSONData:Data) -> AnyObject?
    {
        return Mapper<SWTodayContentFetchRsp>().map(JSONString: JSONString)
    }
    
    override func load()
    {
        DispatchQueue.global(qos: .default).async {
            if let url = Bundle.main.url(forResource: "today", withExtension: "json"),
                let data = try? Data(contentsOf: url)
            {
                self.didFinishLoading(data, cache: true)
            }
        }
    }
}

class SWTodayContentFetchRsp: NSObject,Mappable
{
    var code:String?
    var musics:[SWMusicRsp]?
    var banners:[SWBannerRsp]?
    var poetries:[SWPoetryRsp]?
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        code       <- map["Statu"]
        banners    <- map["BaseModle.yiyatalks"]
        musics     <- map["BaseModle.dailyMusics"]
        poetries   <- map["BaseModle.dailyReads"]
    }
}

class SWBannerRsp: NSObject,Mappable
{
    var id:Int?
    var title:String?
    var imageURL:String?
    var contentURL:String?
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        id              <- map["id"]
        title           <- map["title"]
        imageURL        <- map["imageUrl"]
        contentURL      <- map["wapUrl"]
    }
}
